//
//  MyMatePeopleListViewController.m
//  TQY
//
//  Created by 甘世清 on 2024/10/11.
//

#import "MyMatePeopleListViewController.h"
#import "MatePeopleRequstTableViewCell.h"
@interface MyMatePeopleListViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation MyMatePeopleListViewController

- (void)SQ_viewWillAppear:(BOOL)animated{
    if (self.jsonArray.count<=0) {
        [self SQ_Header];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.zx_navTitle =  SQNSLocalString(@"已申请搭子");
    
}
- (void)SQ_UIViewForSelfView{
    
    self.tableView.delegate  = self;
    self.tableView.dataSource = self;
    [self.view  addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.zx_navBar.mas_bottom);
    }];
    [self SQ_tableViewAddRefresh];
}

 
-(void)SQ_Header{
   NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
   [dic setObject:self.model.userid forKey:@"id"];
   [dic setObject:@"1" forKey:@"current"];
   [dic setObject:@"20" forKey:@"size"];
   [HttpTool post:@"lug/verifyList" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
       self.page = 1;
       NSDictionary * data = [[NSDictionary alloc]initWithDictionary:httpModel.data];
       NSArray * array = [MateModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"records"]];
       [self.jsonArray removeAllObjects];
       [self.jsonArray addObjectsFromArray:array];
       [self.tableView.mj_header endRefreshing];
       [self.tableView reloadData];
   } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
       [YJProgressHUD  showMsgWithoutView:httpModel.message];
       [self.tableView.mj_header endRefreshing];
   }];
 
}
-(void)SQ_Foother{
   NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
   [dic setObject:self.model.userid forKey:@"id"];
   [dic setObject:[NSString stringWithFormat:@"%d",self.page+1] forKey:@"current"];
   [dic setObject:@"20" forKey:@"size"];
   [HttpTool post:@"lug/verifyList" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
       self.page ++;
       NSDictionary * data = [[NSDictionary alloc]initWithDictionary:httpModel.data];
       NSArray * array = [MateModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"records"]];
       [self.jsonArray addObjectsFromArray:array];
       [self.tableView.mj_footer endRefreshing];
       [self.tableView reloadData];
   } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
       [YJProgressHUD  showMsgWithoutView:httpModel.message];
       [self.tableView.mj_footer endRefreshing];
   }];
  
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.jsonArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   MatePeopleRequstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MatePeopleRequstTableViewCell"];
   if (!cell) {
       cell = [[MatePeopleRequstTableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"MatePeopleRequstTableViewCell"];
   }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    MateModel * model = [self.jsonArray objectAtIndex:indexPath.item];
    cell.model = model;
    WS(weakSelf);
    [cell.addBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_addPeople:model];
    }];
    [cell.jujueBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_jujuePeople:model];
    }];
   return cell;

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  
    return [MatePeopleRequstTableViewCell FSCellHeightForTableView:tableView indexPath:indexPath cellContentViewWidth:0 bottomOffset:20];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
}
-(void)SQ_addPeople:(MateModel*)model{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:model.uid forKey:@"uid"];
    [dic setObject:@"2" forKey:@"status"];
    [dic setObject:self.model.userid forKey:@"pid"];
    [HttpTool post:@"lug/verify" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        [self.jsonArray removeObject:model];
        [self.tableView reloadData];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}
-(void)SQ_jujuePeople:(MateModel*)model{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:model.uid forKey:@"uid"];
    [dic setObject:@"1" forKey:@"status"];
    [dic setObject:self.model.userid forKey:@"pid"];
    [HttpTool post:@"lug/verify" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        [self.jsonArray removeObject:model];
        [self.tableView reloadData];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}
@end
